<?php 

ini_set("memory_limit", "64M");
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
function CompareNameASC($a, $b){
	if ($a[1] == $b[1]) {
		return 0;
	}
	return ($a[1] < $b[1]) ? -1 : 1;;
}
function CompareNameDESC($a, $b){
	if ($a[1] == $b[1]) {
		return 0;
	}
	return ($a[1] > $b[1]) ? -1 : 1;;
}

function CompareDateASC($a, $b){
	if ($a[2] == $b[2]) {
		return 0;
	}
	return ($a[2] < $b[2]) ? -1 : 1;;
}
function CompareDateDESC($a, $b){
	if ($a[2] == $b[2]) {
		return 0;
	}
	return ($a[2] > $b[2]) ? -1 : 1;;
}

function CompareCarnumASC($a, $b){
	if ($a[3] == $b[3]) {
		return 0;
	}
	return ($a[3] < $b[3]) ? -1 : 1;;
}
function CompareCarnumDESC($a, $b){
	if ($a[3] == $b[3]) {
		return 0;
	}
	return ($a[3] > $b[3]) ? -1 : 1;;
}
 
if (isset($_SESSION['mylistcarnum']) and is_array($_SESSION['mylistcarnum'])) {
	$winH = 350;
	if(isset($_REQUEST['winH'])) $winH = $_REQUEST['winH'];
	$mylistcarnum = $_SESSION['mylistcarnum'];
	if ($_REQUEST['flag']=='10') {
		usort($mylistcarnum, 'CompareNameASC');
	}elseif($_REQUEST['flag']=='11'){
		usort($mylistcarnum, 'CompareNameDESC');
	}
	elseif($_REQUEST['flag']=='20'){
		usort($mylistcarnum, 'CompareDateASC');
	}elseif($_REQUEST['flag']=='21'){
		usort($mylistcarnum, 'CompareDateDESC');
	}
	elseif($_REQUEST['flag']=='30'){
		usort($mylistcarnum, 'CompareCarnumASC');
	}elseif($_REQUEST['flag']=='31'){
		usort($mylistcarnum, 'CompareCarnumDESC');
	}
	$index = 0;
	foreach ($mylistcarnum as $key =>$row){
	//array($row[id],$row[name],$row[car_datetime],$row[carnumber],$row[host],$row[filename],$row[isReg]);
		 ?>
		 <tr class="trkhac" onclick = "SelectCar(this,'<?=$row[3]?>','select<?=$index?>')" values="<?=$index?>">
		 	<td width="5%" align="center"><input type="checkbox" onclick="SelectCarcheck('select<?=$index?>')" id="select<?=$index?>" class="checkCarnum" name="checkCarnum[<?=$index?>]"/>
		 	<input type="hidden" class="carid"/></td>
		 	<td width="5%" align="center"><?=$index?></td>
		 	<td width="43%" align="center"><?=$row[1]?></td>
		 	<td width="25%" align="center"><?=$row[2]?></td>
		 	<td class="last" align="center"><?=$row[3]?>
		 	</td>
		 </tr>  
		 <?php 
		 $index+=1;
				
	}  
	if ($index>0 and $index<$winH/28) {
	 	foreach(range(0,$winH/28-$index) as $i){
	 		?>
	 		<tr>
		 	<td width="5%">&nbsp;</td>
		 	<td width="5%">&nbsp;</td>
		 	<td width="35%">&nbsp;</td>
		 	<td width="25%">&nbsp;</td>
		 	<td  class="last">&nbsp;</td>
		 	</tr>
	 	<?php }
	}	
	$_SESSION['mylistcarnum'] = $mylistcarnum ;
	  
}
?>

